﻿@model QizSession
@{ 
    var tm = new QizItem() { SortIdx = 1 };
    var exts = new string[] { ".png", ".jpg", ".jpeg", ".gif" };

    string PostControllerName = ViewBag.ModiffyControllerName != null ? ViewBag.ModiffyControllerName : "Home";

    ViewBag.Index = 1;


    var PreviewOnly = ViewBag.ForceEdit != true && (Model.ID != "-1" || "True".Equals(Request["PreviewOnly"], StringComparison.CurrentCultureIgnoreCase));

    if (Request["IsDebug"] == "True")
    {
        PreviewOnly = false;
    }

    bool skipSub = true;
    skipSub = "True".Equals(Request["SkipSub"], StringComparison.CurrentCultureIgnoreCase);


    bool isEditorHasThisSession = Model.UserID == Guid.Empty || Model.UserID == SiteUser.UserId ||
        Model.QizSubject.QizSubjectObjForDoctors.Any(t => t.DoctorID == SiteUser.UserId) ||
        (SiteUser.IsDoctorDepManager && Model.QizSubject.DepID == SiteUser.DepartmentID);

    //是否只显示异常指标 wenke 2014/3/11
    //bool DeviantOnly = PreviewOnly && !String.IsNullOrEmpty(Request["DeviantOnly"])
    //    && "True".Equals(Request["DeviantOnly"], StringComparison.CurrentCultureIgnoreCase);

}
@{
    TempData["FileExts"] = exts;
    TempData["PreviewOnly"] = PreviewOnly;
    TempData["skipSub"] = skipSub;
    TempData["OriQizSessionModel"] = Model;
    TempData["QuizIndex"] = 1;
}
<link type="text/css" rel="Stylesheet" href="@Url.Content("~/Content/QizSessionEdit.css")"/>
@*@if (PreviewOnly && !skipSub)
{
    @Html.Partial("QsdRenders/AnchorsList", Model)
}*@
@using (Html.BeginForm("QizSessionEdit", PostControllerName, null, FormMethod.Post, new { enctype = "multipart/form-data", id = "SessionForm" }))
{
    if (PreviewOnly && !skipSub)
    {
    <a name="Subject_@(Model.QizSubject.ID)" id="Subject_@(Model.QizSubject.ID)"></a>
    }
    <div>
        @Html.Hidden("RecuperID", Model.ID)
        @Html.Hidden("TokenID", (string)ViewBag.TokenID)
        @Html.Partial("QsdRenders/Header", Model)
        @Html.Partial("QsdRenders/MessageAndWarnning", Model)
        <fieldset style="padding: 10px;">
            <legend></legend>
            @Html.HiddenFor(model => model.ID)
            @Html.HiddenFor(model => model.QizSubjectID)
            @Html.HiddenFor(model => model.PID)
            @*            <img alt="检查时间(必须填写)" src="@Url.Content("~/Content/Images/checkClock.png")" style="padding: 0px;vertical-align: middle" />*@
            @*<div class="editor-label error" data-icon="edit">
                <h3>*检查时间：</h3>
            </div>*@
            <div class="editor-field">
                @Html.EditorFor(model => model.Timemark, "TxtField") 
                <span style="display:none">@DateTime.Now | @DateTime.UtcNow</span> 
            </div>
            @*@if (DeviantOnly)
            {
                <div class="editor-field">
                    <input type="radio" id="btn_devqiz" class="dev-filter" name="devfilter" value="1" onclick="devFilter(1);" checked="checked" />
                    <label for="btn_devqiz">异常指标</label>
                    <input type="radio" id="btn_allqiz" class="dev-filter" name="devfilter" value="2" onclick="devFilter(2);"/>
                    <label for="btn_allqiz">全部指标</label>
                </div>
            }*@
            @Html.Partial("QsdRenders/QsdBody", new QsdRenderModel()
                   {
                       AllSubItems = Model.QizSessionDetails.Where(v => string.IsNullOrEmpty(v.QizSubjectDefine.ParentSubjDefID)).OrderBy(v => v.QizSubjectDefine.SortIdx),
                       CurrentDeepLvl = 0,
                       ParentID = "root",
                       CurrentItem = null
                   })

            @{

            }
            <p style="@(!PreviewOnly && isEditorHasThisSession ? "" : "display:none")">
                @if (!PreviewOnly && isEditorHasThisSession)
                {
                    <input type="submit" value="提交" onclick="var r = confirm('请确认是否提交随访内容，提交后的随访将无法修改。\r\n\r\n建议您一定要对填写的内容作充足的检查以避免收到不正确的诊断提示。\r\n\r\n请问是否提交？'); if (r) $(this).hide(); return r;" />
                }
                else
                { 
                    <input type="submit" value="提交" disabled="disabled" />
                }
            </p>
        </fieldset>
    </div>
}

@if (SiteUser.IsDoctorDepManager && Model.QizSubject.DepID == SiteUser.DepartmentID)
{
    using (Ajax.BeginForm("TianBaoZhiLiangEdit", new AjaxOptions()
    {
        LoadingElementId = "OnLoadingSpan",
        UpdateTargetId = "",
        InsertionMode = InsertionMode.Replace,
        HttpMethod = "Post",
        OnSuccess = "alert('操作成功。')",
        OnFailure = "OnSiteError"
    }))
    {
    <span class="small-input">填报质量评价：
        @Html.Hidden("SessionID", Model.ID)
        @Helpers.RadioList("TianBaoZhiLiang", "重复,空白,无效,未处理,填写".Split(','), "重复,空白,无效,未处理,填写:".Split(','), 4, true)
        @Html.TextBox("TianBaoZhiLiang_Other", Model.TianBaoZhiLiang)</span>
    <input type="submit" value="提交" />
    }
}

<script type="text/javascript">
    $(function () {
        $('input:submit').button({
            icons: {
                primary: "ui-icon-locked"
            }
        });
    });
</script>
@if (!PreviewOnly)
{
    <script type="text/javascript">
        $(function () {
            $("#SessionForm :radio").not('.dev-filter').change(function () {
                $(this).closest("li.quiz-item-body").find("ul").hide("swing");
                $(this).closest("li.quiz-item-body").find("ul").find('input,select').prop("disabled", true);
                $(this).closest("li.quiz-item-body").find("ul#" + $(this).attr("selitemsubid")).show("swing");
                $(this).closest("li.quiz-item-body").find("ul#" + $(this).attr("selitemsubid")).find('input,select').prop("disabled", false);
            });

            $("#SessionForm :radio:checked").not('.dev-filter').each(function () { $(this).closest("li.quiz-item-body").find("ul#" + $(this).attr("selitemsubid")).show("swing"); })

        });


    </script>
}
else
{ 
    <script type="text/javascript">
        $("#SessionForm input").not('.dev-filter').attr("disabled", true);
        $("#SessionForm select").not('.dev-filter').attr("disabled", true);

        $(function () {
            $("#SessionForm input").not('.dev-filter').attr("disabled", true);
            $("#SessionForm select").not('.dev-filter').attr("disabled", true);
            $("#SessionForm :radio:checked").not('.dev-filter').each(function () { $(this).closest("li.quiz-item-body").find("ul#" + $(this).attr("selitemsubid")).show("swing"); })

        });

    </script>
}
@*@if (DeviantOnly)
{
    <script type="text/javascript">
        function reverseShow(selector) {
            var prevqiz = $(selector).prev();
            if (prevqiz && prevqiz.hasClass('quiz-group-title')) {
                prevqiz.show();
                reverseShow(prevqiz);
            }
        };
        function devFilter(t) {
            if (t == 1) {
                $('.normalqiz').hide();
                $('.deviantqiz .enumvalues li').each(function (i, el) {
                    if ($(this).find('input:checked').length == 0) {
                        $(this).hide();
                    }
                });

                $('.quiz-group-title').each(function () {
                    var id = $(this).attr('id');                    
                    if ($('.deviantqiz[data-parent="' + id + '"]').length == 0) {
                        $(this).hide();
                    } else {
                        reverseShow(this);
                    }
                });
            } else {
                $('.normalqiz').show();
                $('.deviantqiz .enumvalues li').show();
                $('.quiz-group-title').show();
            }
        };
        $(function () {
            devFilter(1); //只显示异常指标
        });
    </script>
}*@
<style type="text/css">
    ul.qizdetails {
        padding: 0;
        margin: 0;
    }

        ul.qizdetails ul.qizdetails {
            padding-left: 1em;
            margin: 0;
        }

    .qizdetails ol {
        padding-left: 0;
        margin: 0;
    }

    .qizdetails li {
        list-style: none;
        line-height: 32px;
        background-color: #f1f1f1; /*border-bottom: 2px solid white;*/
    }

    .quiz-group-title {
        font-size: 1.2em;
    }
    /*.qizdetails label.ui-btn
        {
            background-color: white !important;
            font-size:0.8em;
            color:#222;
            height:28px;
            line-height:28px;
        }*/
    .error-title { /*float: left;*/
        width: 100%;
        background-color: #f1f1f1;
        background-image: url(/Content/Images/vertical-red.png);
        background-repeat: no-repeat;
        font-weight: bold;
        line-height: 2em;
        padding-left: 10px;
    }

    .field-validation-error {
        color: #f00;
        display: inline !important;
        margin-top: 0px !important;
        text-align: left !important;
    }
    .ui-collapsible {
        margin-left:0 !important;
        margin-right:0 !important;
    }
    .ui-collapsible-content {
        padding-bottom: 1em !important;
        padding-left:1em !important;
        padding-right:0.5em !important;        
    }
    .warnning-block ol {
        margin:0px;
        padding:0px;
    }
        .warnning-block ol li {
            margin:0.5em 0.5em 0 1em;
            font-size:1em;
            font-weight:bold;
            color:red;
        }
    .warnning-block h4 {
        display: inline;
    }          
</style>
@if (PreviewOnly)
{
    <script type="text/javascript">
        $(function () {
            var blockctrl = [
                { ctrl: '#ctrl-descifbad', block: '#block-descifbad' },
                { ctrl: '#ctrl-desciffine', block: '#block-desciffine' },
                { ctrl: '#ctrl-hospdepart', block: '#block-hospdepart' },
                { ctrl: '#ctrl-deviant', block: '#block-deviant' }
            ];
            $.each(blockctrl, function (i, item) {
                $(item.block).hide();
                $(item.ctrl).click(function () {
                    if ($(item.block).is(':hidden')) {
                        $(item.block).show();
                    } else {
                        $(item.block).hide();
                    }
                });
            });
            $('#block-deviant').show();
        });
    </script>
}
@*else
{
    <script type="text/javascript">
        $(function () {
            var blockctrl = [
                { ctrl: '#ctrl-hospdepart', block: '#block-hospdepart' },
                { ctrl: '#ctrl-note', block: '#block-note' }
            ];
            $.each(blockctrl, function (i, item) {
                $(item.block).hide();
                $(item.ctrl).click(function () {
                    if ($(item.block).is(':hidden')) {
                        $(item.block).show();
                    } else {
                        $(item.block).hide();
                    }
                });
            });
        });
    </script>
}*@